package com.atguigu.lease.web.app.service.impl;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.atguigu.lease.web.app.service.SmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SmsServiceImpl implements SmsService {

	@Autowired
	private Client client;

	@Override
	public void sendCode(String phone, String code) {
		SendSmsRequest sendSmsRequest = new SendSmsRequest();
		// 目标手机号
		sendSmsRequest.setPhoneNumbers(phone);
		// 签名名称
		sendSmsRequest.setSignName("阿里云短信测试");
		// 模板编码
		sendSmsRequest.setTemplateCode("SMS_154950909");
		// 模板参数
		sendSmsRequest.setTemplateParam("{\"code\":\"" + code + "\"}");

		try {
			// 发送请求
			client.sendSms(sendSmsRequest);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}
